package net.xiangcaowuyu.activemqdemo.controller;

import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.jms.Queue;
import javax.jms.Topic;

/**
 * 博客：https://www.xiangcaowuyu.net
 * Description:
 *
 * @Author: 香草物语
 * DateTime: 2021-07-20 14:41
 */
@RestController
public class ProducerController {

    @Resource
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Resource
    private Queue queue;

    @Resource
    private Topic topic;

    @RequestMapping("/sendQueueMessage/{msg}")
    public String sendQueueMessage(@PathVariable("msg") String msg) {
        this.jmsMessagingTemplate.convertAndSend(queue, msg);
        return msg;
    }

    @RequestMapping("/sendTopicMessage/{msg}")
    public String sendTopicMessage(@PathVariable("msg") String msg) {
        this.jmsMessagingTemplate.convertAndSend(topic, msg);
        return msg;
    }

}
